local fk__xiaorong = fk.CreateSkill {

  name = "fk__xiaorong",

  tags = {  },

}

local U = require "packages/utility/utility"


fk__xiaorong:addEffect(fk.AfterCardTargetDeclared, {

  anim_type = "offensive",

  can_trigger = function (self, event, target, player, data)
    return target == player and player:hasSkill(fk__xiaorong.name) and data.card.trueName == "slash" and
      data:isOnlyTarget(data.tos[1]) and
      table.find(player.room.alive_players, function (p)
        return p:distanceTo(player) == 1
      end) and #data:getExtraTargets() > 0
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local targets = data:getExtraTargets()
    local num = #table.filter(player.room.alive_players, function (p)
      return p:distanceTo(player) == 1
    end)
    local tos = room:askToChoosePlayers(player,
    {
    targets = targets,
    min_num = 1,
    max_num = num,
    prompt = "#fk__xiaorong:::" .. num,
    skill_name = fk__xiaorong.name,
    cancelable = true,
    })
    if #tos > 0 then
      event:setCostData(self, {tos = tos})
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    table.forEach(event:getCostData(self).tos, function (p)
      data:addTarget(p)
    end)
    if #data:getAllTargets() > player.hp then
      data:changeCard("duel",data.card.number,data.card.suit)
    end
  end,
})

return fk__xiaorong